home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / atexit.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  2KB  |  74 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''
  5. atexit.py - allow programmer to define multiple exit functions to be executed
  6. upon normal program termination.
  7.  
  8. One public function, register, is defined.
  9. '''
  10. __all__ = [
  11.     'register']
  12. import sys
  13. _exithandlers = []
  14.  
  15. def _run_exitfuncs():
  16.     '''run any registered exit functions
  17.  
  18.     _exithandlers is traversed in reverse order so functions are executed
  19.     last in, first out.
  20.     '''
  21.     exc_info = None
  22.     while _exithandlers:
  23.         (func, targs, kargs) = _exithandlers.pop()
  24.         
  25.         try:
  26.             func(*targs, **kargs)
  27.         continue
  28.         except SystemExit:
  29.             exc_info = sys.exc_info()
  30.             continue
  31.             import traceback as traceback
  32.             print >>sys.stderr, 'Error in atexit._run_exitfuncs:'
  33.             traceback.print_exc()
  34.             exc_info = sys.exc_info()
  35.             continue
  36.         
  37.  
  38.     if exc_info is not None:
  39.         raise exc_info[0], exc_info[1], exc_info[2]
  40.  
  41.  
  42. def register(func, *targs, **kargs):
  43.     '''register a function to be executed upon normal program termination
  44.  
  45.     func - function to be called at exit
  46.     targs - optional arguments to pass to func
  47.     kargs - optional keyword arguments to pass to func
  48.  
  49.     func is returned to facilitate usage as a decorator.
  50.     '''
  51.     _exithandlers.append((func, targs, kargs))
  52.     return func
  53.  
  54. if hasattr(sys, 'exitfunc'):
  55.     register(sys.exitfunc)
  56. sys.exitfunc = _run_exitfuncs
  57. if __name__ == '__main__':
  58.     
  59.     def x1():
  60.         print 'running x1'
  61.  
  62.     
  63.     def x2(n):
  64.         print 'running x2(%r)' % (n,)
  65.  
  66.     
  67.     def x3(n, kwd = None):
  68.         print 'running x3(%r, kwd=%r)' % (n, kwd)
  69.  
  70.     register(x1)
  71.     register(x2, 12)
  72.     register(x3, 5, 'bar')
  73.     register(x3, 'no kwd args')
  74.